﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GLCDDesigner2
{
    using System.Reflection;

    using GLCDBaseTypes.BaseTypes;
    using GLCDBaseTypes.PluginInterfaces;

    public partial class BitmapConversionForm : Form
    {
        public BitmapConversionForm()
        {
            InitializeComponent();

            Assembly moduleAssembly = Assembly.LoadFrom(@"C:\Users\Jelle\Documents\Visual Studio 2010\Projects\GLCDDesigner\GLCDST7565Plugin\bin\Debug\GLCDST7565Plugin.dll");

            Type[] types = moduleAssembly.GetTypes();

            foreach (var instance in
                from type in types
                where type.GetInterface("ILcdPlugin") != null
                select (ILcdPlugin)Activator.CreateInstance(type))
            {
                this.toolStripComboBox1.Items.Add(instance);
            }

            this.toolStripComboBox1.SelectedIndex = 0;
        }

        private void openToolStripButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() != System.Windows.Forms.DialogResult.Cancel)
            {
                Bitmap bmp = new Bitmap(openFileDialog1.FileName);

                pictureBoxOriginal.Image = bmp;

                richTextBox1.Text = ((ILcdPlugin)toolStripComboBox1.SelectedItem).GetArduinoCode(bmp, toolStripTextBox1.Text);

                List<HexRepresentationItem> hexItems2 = ((ILcdPlugin)toolStripComboBox1.SelectedItem).GetHexList(bmp);

                Bitmap bmp2 = ((ILcdPlugin)toolStripComboBox1.SelectedItem).CreateBitmapFromHex(hexItems2, bmp.Width, 1);
                pictureBoxLCDVersion.Image = bmp2;
            }
        }
    }
}
